package com.calmcar.adas.util;

import com.calmcar.adas.apiserver.AdasConf;

/**
 * Created by lelexiao on 2018/4/8.
 */

public class CarSafeDistanceUtil {
    public CarSafeDistanceUtil(){
    }
    private double safeDisOld=500;
    private double safeBaseValue=360;
    private double safeABSDisOld=150;
    public  int   checkIsValidSafeDistanceForAPI (double y  ,double rate){
//       double < 3.6 < 1.8  360-260=100;100/35=2.8s-10  360-300=60/35=1.7m -6S    30/35=1s-3s
//        //5米-2米
//        public static int  CAR_CRASH_AREA_TOP_Y= 310,//292,
//                CAR_CRASH_AREA_BOTTOM_Y= 330;
//        //15米-10米
//        public static int  CAR_SAFE_DISTANCE_AREA_TOP_Y =260,//271,
//                CAR_SAFE_DISTANCE_AREA_BOTTOM_Y= 300;

//       safeDisOld=y;
         if(AdasConf.VP_Y>20){
             safeBaseValue= 360+(AdasConf.VP_Y-AdasConf.IN_FRAME_HEIGHT/2) ;
         }else{
             safeBaseValue= 360;
         }
         double meterRate=   rate/3.6;
         double distance=    safeBaseValue-y;
         double ressponeTime=distance/meterRate;
         if(ressponeTime< AdasConf.CAR_WARN_LEVEL_ONE_TIME){
             if( y >safeDisOld){
                 safeDisOld=y;
                 return 1;
             }else{
                 safeDisOld=y;
             }
         }else if (ressponeTime< AdasConf.CAR_WARN_LEVEL_TWO_TIME) {
             if( y >safeDisOld){
                 safeDisOld=y;
                 return 2;
             }else{
                 safeDisOld=y;
             }
         }else{
             return 0;
         }
         return 0;
    }


    public  int   checkIsValidSafeABSDistanceForAPI (double y  ,double rate){
//        double distance=   y;
        double meterRate=   rate/3.6;
        double ressponeTime=y/meterRate;
        if(ressponeTime< AdasConf.CAR_WARN_ABS_LEVEL_ONE_TIME +AdasConf.FCW_WARN_LEVEL*0.2){//3 +1.5
            if( y< safeABSDisOld){
                safeABSDisOld=150;
                return 1;
            }else{
                safeABSDisOld=y;
            }
        }else if (ressponeTime< AdasConf.CAR_WARN_ABS_LEVEL_TWO_TIME+AdasConf.FCW_WARN_LEVEL*0.1) {//0.5+1.5
            if( y< safeABSDisOld){
                safeABSDisOld=150;
                return 2;
            }else{
                safeABSDisOld=y;
            }
        }else{
            return 0;
        }
        return 0;
    }



    public  int   checkIsValidSafeABSDistanceForAPITest (double y  ,double rate){
//        double distance=   y;
        double meterRate=   rate/3.6;
        double ressponeTime=y/meterRate;
        if(ressponeTime< AdasConf.CAR_WARN_ABS_LEVEL_ONE_TIME +AdasConf.FCW_WARN_LEVEL*0.2){//3 +1.5
           return  1;
        }else if (ressponeTime< AdasConf.CAR_WARN_ABS_LEVEL_TWO_TIME+AdasConf.FCW_WARN_LEVEL*0.1) {//0.5+1.5
           return 2;
        }else{
            return 0;
        }

    }


}
